package org.xlx.xlx_oa.warehouse.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.xlx.xlx_oa.common.ResponseBean;
import org.xlx.xlx_oa.role_user.domain.vo.AuditVo;
import org.xlx.xlx_oa.warehouse.api.WarehouseApplyApi;
import org.xlx.xlx_oa.warehouse.domain.vo.WarehouseApplyVo;
import org.xlx.xlx_oa.warehouse.service.WarehouseApplyService;

@RestController
@RequestMapping("/v1/warehouse-apply")
public class WarehouseApplyController implements WarehouseApplyApi {
    @Autowired
    private WarehouseApplyService warehouseApplyService;

    @PostMapping("/save")
    @Override
    public ResponseBean saveApply(@RequestBody WarehouseApplyVo applyVo) {
        return ResponseBean.successFactory(warehouseApplyService.saveApply(applyVo));
    }

    @PostMapping("/beAudit/list")
    @Override
    public ResponseBean getBeAuditList(@RequestBody WarehouseApplyVo applyVo) {
        return ResponseBean.successFactory(warehouseApplyService.getBeAuditList(applyVo));
    }

    @PostMapping("/beAudit/count")
    @Override
    public ResponseBean getBeAuditCount(@RequestBody WarehouseApplyVo applyVo) {
        return ResponseBean.successFactory(warehouseApplyService.getBeAuditedCount(applyVo));
    }

    @PostMapping("/apply/list")
    @Override
    public ResponseBean getApplyList(@RequestBody WarehouseApplyVo applyVo) {
        return ResponseBean.successFactory(warehouseApplyService.getApplyList(applyVo));
    }

    @PostMapping("/apply/count")
    @Override
    public ResponseBean getApplyCount(@RequestBody WarehouseApplyVo applyVo) {
        return ResponseBean.successFactory(warehouseApplyService.getAppliedCount(applyVo));
    }

    @PostMapping("/maxCount")
    @Override
    public ResponseBean getMaxCount(
            @RequestParam(value = "facilityId") Long facilityId,
            @RequestParam(value = "type") String type) {
        return ResponseBean.successFactory(warehouseApplyService.getCountByFacilityId(facilityId, type));
    }

    @GetMapping("/detail/{id}")
    @Override
    public ResponseBean getApplyDetail(@PathVariable(value = "id") Long id) {
        return ResponseBean.successFactory(warehouseApplyService.getDetail(id));
    }

    @PostMapping("/audit")
    @Override
    public ResponseBean audit(@RequestBody AuditVo auditVo) {
        return ResponseBean.successFactory(warehouseApplyService.updateAudit(auditVo));
    }
}

